using System.Web.Mvc;
using iHouse.Model.Repository.Interface;
using Microsoft.Practices.Unity;
using iHouse.Model.Data;
using iHouse.Infrastructure;
using iHouse.Common.Configuration;
using iHouse.Web.Infrastructure;

namespace iHouse.Web.Controllers
{
    public class AlbumController : BaseController
    {
        [Dependency]
        public IAlbumRepository AlbumRepository { get; set; }

        protected override CategoryType ControllerType
        {
            get { return CategoryType.Album; }
        }

        protected override int DefaultPageSize
        {
            get
            {
                return IHouseSection.Current.Album.PageSize;
            }
        }

        public ActionResult HomeList(int? category, int? page, [PaingCriteriaBinder(typeof(AlbumSearchFilter), SearchOperator.Or)]PagingCriteria pagingCriteria)
        {
            PaginationList<Album> result;

            if (category.HasValue)
            {
                result = this.AlbumRepository.FindEntitiesByCategory(category.Value, page.HasValue ? page.Value : 1, DefaultPageSize);
            }
            else
            {
                pagingCriteria.PageSize = DefaultPageSize;
                pagingCriteria.PageIndex = page.HasValue ? page.Value : 1;
                result = this.AlbumRepository.FindEntities(pagingCriteria);
            }

            ViewBag.TypeCategories = this.Categories;
            return View(result);
        }

    }
}
